from django.contrib.auth.models import AbstractUser, Group, Permission
from django.db import models
from django.utils import timezone


class BlogUser(AbstractUser):
    phone_number = models.CharField(max_length=15, blank=True,verbose_name="用户手机号")
    avatar = models.ImageField(upload_to='avatars/', null=True, blank=True,verbose_name="用户logo")
    date_visited = models.DateTimeField(verbose_name="访问时间",default=timezone.now, null=True, blank=True)
    # 添加 related_name 参数解决与内置用户模型字段的冲突
    groups = models.ManyToManyField(
        Group,
        verbose_name='groups',
        blank=True,
        help_text='The groups this user belongs to.',
        related_name='bloguser_set',  # 为 groups 添加 related_name 参数
        related_query_name='bloguser',
    )
    user_permissions = models.ManyToManyField(
        Permission,
        verbose_name='user permissions',
        blank=True,
        help_text='Specific permissions for this user.',
        related_name='bloguser_set',  # 为 user_permissions 添加 related_name 参数
        related_query_name='bloguser',
    )
    class Meta:
        verbose_name = '博客注册用户表'
        verbose_name_plural = verbose_name